package com.itheima.mm.entity;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @author ：songyu
 * @date ：Created in 2023/8/24
 * @description : 封装正常返回结果
 * @version: 1.0
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class Result<T> implements java.io.Serializable {
	private boolean flag;//执行结果，true为执行成功 false为执行失败
	private String message;//返回结果信息
	private T result;//返回数据


	public static <T> Result<T> success() {
		Result<T> result = new Result<T>();
		result.flag = true;
		return result;
	}

	public static <T> Result<T> success(T object) {
		Result<T> result = new Result<T>();
		result.result = object;
		result.flag = true;
		return result;
	}

	public static <T> Result<T> success(T object,String message) {
		Result<T> result = new Result<T>();
		result.result = object;
		result.flag = true;
		result.message = message;
		return result;
	}

	public static <T> Result<T> error(String msg) {
		Result result = new Result();
		result.message = msg;
		result.flag = false;
		return result;
	}
}
